package com.sugon.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.DevEquFileDao;
import com.sugon.entity.DevEquFileEntity;
import com.sugon.service.DevEquFileService;
import com.sugon.utils.Constant;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 设备档案附件关系类Service实现类
 *
 * @author sugon
 * @date 2020-12-24 10:59:39
 */
@Service("devEquFileService")
public class DevEquFileServiceImpl implements DevEquFileService {
    @Autowired
    private DevEquFileDao devEquFileDao;

    /**
     * queryObject
     *
     * @param id 主键
     * @return
     */
    @Override
    public DevEquFileEntity queryObject(String id) {
        return devEquFileDao.queryObject(id);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<DevEquFileEntity> queryList(Map<String, Object> map) {
        return devEquFileDao.queryList(map);
    }

    /**
     * queryList
     *
     * @param devId      设备ID
     * @param fileTypeId 资料类别ID
     * @return
     */
    @Override
    public List<DevEquFileEntity> queryList(String devId, String fileTypeId) {
        Map<String, Object> map = new HashMap<>();
        map.put("devId", devId);
        map.put("fileTypeId", fileTypeId);
        return queryList(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return devEquFileDao.queryTotal(map);
    }

    /**
     * save
     *
     * @param devEquFile 实体
     * @return
     */
    @Override
    public int save(DevEquFileEntity devEquFile) {
        devEquFile.setId(RandomUtil.randomString(32));
        devEquFile.setCreateDate(DateUtil.date());
        devEquFile.setCreateUser(ShiroUtils.getUserId());
        devEquFile.setUpdateDate(devEquFile.getCreateDate());
        devEquFile.setUpdateUser(devEquFile.getCreateUser());
        devEquFile.setDelFlag(Constant.IS_NOT_DEL_INT);
        return devEquFileDao.save(devEquFile);
    }

    /**
     * update
     *
     * @param devEquFile 实体
     * @return
     */
    @Override
    public int update(DevEquFileEntity devEquFile) {
        devEquFile.setUpdateDate(DateUtil.date());
        devEquFile.setUpdateUser(ShiroUtils.getUserId());
        return devEquFileDao.update(devEquFile);
    }

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return devEquFileDao.delete(id);
    }

    /**
     * deleteBatch
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return devEquFileDao.deleteBatch(ids);
    }
}
